package net.xdclass.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

public class CartVO {

    @JsonProperty("car_items")
    private List<CartItemVO> cartItems;

    @JsonProperty("total_num")
    private Integer totalNum;

    @JsonProperty("total_amount")
    private BigDecimal totalAmount;

    @JsonProperty("real_pay_amount")
    private BigDecimal realPayAmount;


    public List<CartItemVO> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItemVO> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getTotalNum() {
        if(!CollectionUtils.isEmpty(cartItems)){
            return cartItems.stream().mapToInt(CartItemVO::getBuyNum).sum();
        }
        return 0;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal amount = new BigDecimal(0);
        if (!CollectionUtils.isEmpty(cartItems)) {
            for (CartItemVO c : cartItems) {
                amount.add(c.getTotalAmount());
            }
        }
        return amount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getRealPayAmount() {
        BigDecimal amount = new BigDecimal(0);
        if (!CollectionUtils.isEmpty(cartItems)) {
            for (CartItemVO c : cartItems) {
                amount.add(c.getTotalAmount());
            }
        }
        return amount;
    }

    public void setRealPayPrice(BigDecimal realPayAmount) {
        this.realPayAmount = realPayAmount;
    }


}
